package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 根据环信id查询用户详情信息
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId){
        UserInfoVo vo = messagesService.findByHuanxin(huanxinId);

        return ResponseEntity.ok(vo);
    }

    /**
     * 添加联系人
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Integer friendId = (Integer) map.get("userId");
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询联系人列表
     * @param keyword
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity findAllContacts(String keyword,
                                          @RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int pagesize){
        PageResult pageResult = messagesService.findAllContacts(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 公告列表
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") int page,
                                        @RequestParam(defaultValue = "10") int pagesize){
        PageResult pageResult = messagesService.announcements(page,pagesize);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 用户喜欢人列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") int page,
                                @RequestParam(defaultValue = "10") int pagesize){
        PageResult pageResult = messagesService.loves(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 用户点赞列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") int page,
                                @RequestParam(defaultValue = "10") int pagesize){
        PageResult pageResult = messagesService.likes(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 用户评论列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") int page,
                                   @RequestParam(defaultValue = "10") int pagesize){
        PageResult pageResult = messagesService.comments(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
}
